package server.client.handler;

import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.util.SaResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler
    public SaResult handlerHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) {
        log.error("接口 GET/POST 访问方式错误,{}", e.getMessage(), e);
        return SaResult.error("接口访问方式错误").setData(e.getMessage());
    }


    @ExceptionHandler
    public SaResult handlerNotLoginException(NotLoginException e) {
        log.error("Token错误或无效，无法访问此接口,{}", e.getMessage(), e);
        return SaResult.error("Token错误或无效，无法访问此接口").setData(e.getMessage());
    }


    @ExceptionHandler
    public SaResult handlerThrowable(Throwable e) {
        log.error(e.getMessage(), e);
        return SaResult.error().setData(e.getMessage());
    }

}